﻿using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using 初始测试.Tools;

namespace 初始测试
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public ObservableCollection<string> AvaliableVoiceList { get; set; }
        public string selectedVoice = string.Empty;
        public MainWindow()
        {
            InitializeComponent();
            AvaliableVoiceList = new ObservableCollection<string>(AudioHandle.ListSupportedVoice());
            voiceListBox.ItemsSource = AvaliableVoiceList;
        }

        private void startBtn_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                AudioHandle.StartAudioCollect();
            });
            //AudioHandle.ListSupportedAudioFormats();
        }

        private void stopBtn_Click(object sender, RoutedEventArgs e)
        {
            AudioHandle.StopAudioCollect();
        }

        private void parseBtn_Click(object sender, RoutedEventArgs e)
        {
            string word = AudioHandle.ParseWords();
            if (word.Equals("退出系统"))
            {
                Application.Current.Shutdown(0);
            }
            else if (word.Equals("打开弹出框"))
            {
                MessageBox.Show(word);
            }
            txtBox.Text += word + "\r\n";
        }

        private void speekBtn_Click(object sender, RoutedEventArgs e)
        {
            string text = txtBox.Text.Trim();
            AudioHandle.SetVoiceType(selectedVoice);
            Task.Run(() =>
            {
                AudioHandle.SpeekText(text);
            });
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            selectedVoice = (sender as ComboBox).SelectedValue.ToString();
        }
    }
}